package com.example.t470p.facechecktickets.Sax;

import com.example.t470p.facechecktickets.Bean.CheckTicketMessageResult;
import com.example.t470p.facechecktickets.Utils.LogUtil;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class CheckTicketMessageHandler extends DefaultHandler {


    private CheckTicketMessageResult ct;
    private CheckTicketMessageResult.CheckTicketMessageResultBean cb;
    //声明一个字符串变量
    private String content;

    @Override
    public void startDocument() throws SAXException {
        super.startDocument();
        ct = new CheckTicketMessageResult();

    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        super.startElement(uri, localName, qName, attributes);
        if (localName.equals("CheckTicketMessageResult")) {
            cb = new CheckTicketMessageResult.CheckTicketMessageResultBean();
        }

    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        super.characters(ch, start, length);
        content = new String(ch, start, length);
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        super.endElement(uri, localName, qName);
        if (localName.equals("code")) {
            cb.setCode(content);
        } else if (localName.equals("message")) {
            cb.setMessage(content);
        } else if (localName.equals("result")) {
            cb.setResult(content);
        } else if (localName.equals("msg")) {
            cb.setMsg(content);
        } else if (localName.equals("ticketProperty")) {
            cb.setTicketProperty(content);
        } else if (localName.equals("totalMaxNumber")) {
            cb.setTotalMaxNumber(content);
        } else if (localName.equals("gateSoundId")) {
            cb.setGateSoundId(content);
        } else if (localName.equals("ticketName")) {
            cb.setTicketName(content);
        } else if (localName.equals("checkTime")) {
            cb.setCheckTime(content);
        }
    }

    public CheckTicketMessageResult getMessage() {
        ct.setCheckTicketMessageResult(cb);
        return ct;
    }
}
